<template><div><h2 id="菜单基本使用" tabindex="-1"><a class="header-anchor" href="#菜单基本使用"><span>菜单基本使用</span></a></h2>
<p>Dcat Admin 中文文档 /</p>
<h2 id="菜单" tabindex="-1"><a class="header-anchor" href="#菜单"><span>菜单</span></a></h2>
<p><code v-pre>Dcat Admin</code>的菜单是保存在数据表<code v-pre>admin_menu</code>上的，开发者可以在后台菜单管理页面对菜单进行管理。</p>
<h3 id="菜单权限" tabindex="-1"><a class="header-anchor" href="#菜单权限"><span>菜单权限</span></a></h3>
<p>每个菜单都可以与权限或角色进行绑定，如果不设置则为公共菜单，所有账号都能看到。</p>
<p>通过<code v-pre>admin.menu.bind_permission</code>配置参数可以设置是否允许绑定权限。</p>
<h3 id="菜单翻译" tabindex="-1"><a class="header-anchor" href="#菜单翻译"><span>菜单翻译</span></a></h3>
<p>在您的语言文件的menu_titles索引中追加菜单标题。 例如“工作单位”标题：</p>
<p>在<code v-pre>resources/lang/{当前语言}/menu.php</code>中</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token operator">...</span></span>
<span class="line"><span class="token string single-quoted-string">'titles'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'work_units'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Unidades de trabajo'</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="菜单缓存" tabindex="-1"><a class="header-anchor" href="#菜单缓存"><span>菜单缓存</span></a></h3>
<p>通过<code v-pre>admin.menu.cache.enable</code>配置参数可以开启或关闭菜单缓存，建议开启。</p>
<h3 id="通过menu-add接口动态添加菜单" tabindex="-1"><a class="header-anchor" href="#通过menu-add接口动态添加菜单"><span>通过Menu::add接口动态添加菜单</span></a></h3>
<p><code v-pre>Dcat Admin</code>还提供了通过数组的方式在代码中即时添加菜单。</p>
<p>在<code v-pre>app\Admin\bootstrap.php</code>中添加如下代码：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Admin</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Layout<span class="token punctuation">\</span>Menu</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">menu</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Menu</span> <span class="token variable">$menu</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$menu</span><span class="token operator">-></span><span class="token function">add</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'id'</span>            <span class="token operator">=></span> <span class="token string single-quoted-string">'1'</span><span class="token punctuation">,</span> <span class="token comment">// 此id只要保证当前的数组中是唯一的即可</span></span>
<span class="line">            <span class="token string single-quoted-string">'title'</span>         <span class="token operator">=></span> <span class="token string single-quoted-string">'测试菜单'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'icon'</span>          <span class="token operator">=></span> <span class="token string single-quoted-string">'fa-file-text-o'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'uri'</span>           <span class="token operator">=></span> <span class="token string single-quoted-string">''</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'parent_id'</span>     <span class="token operator">=></span> <span class="token number">0</span><span class="token punctuation">,</span> </span>
<span class="line">            <span class="token string single-quoted-string">'permission_id'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'test'</span><span class="token punctuation">,</span> <span class="token comment">// 与权限绑定</span></span>
<span class="line">            <span class="token string single-quoted-string">'roles'</span>         <span class="token operator">=></span> <span class="token string single-quoted-string">'test-roles'</span><span class="token punctuation">,</span> <span class="token comment">// 与角色绑定</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span>  </span>
<span class="line">        <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'id'</span>            <span class="token operator">=></span> <span class="token string single-quoted-string">'2'</span><span class="token punctuation">,</span> <span class="token comment">// 此id只要保证当前的数组中是唯一的即可</span></span>
<span class="line">            <span class="token string single-quoted-string">'title'</span>         <span class="token operator">=></span> <span class="token string single-quoted-string">'测试菜单2'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'icon'</span>          <span class="token operator">=></span> <span class="token string single-quoted-string">'fa-file-text-o'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'uri'</span>           <span class="token operator">=></span> <span class="token string single-quoted-string">'test-menu2'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'parent_id'</span>     <span class="token operator">=></span> <span class="token string single-quoted-string">'1'</span><span class="token punctuation">,</span> </span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span>  </span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="为何没有权限的菜单不会自动隐藏" tabindex="-1"><a class="header-anchor" href="#为何没有权限的菜单不会自动隐藏"><span>为何没有权限的菜单不会自动隐藏？</span></a></h3>
<p>这个问题是因为你没有给菜单绑定权限或者角色，给你想要无权不显示的菜单绑定权限或者角色即可。</p>
</div></template>


